/**
 * Created by Administrator on 2016/12/20.
 */
/*解析href*/
var str = location.search;
str = str.slice(1).split('&');
var json = {};
for (var i = 0; i < str.length; i++) {
    var a = str[i].split('=');
    json[a[0]] = a[1];
}
console.log(json);

/*工人出勤明细获取*/
var
    oDataTime           = $('#dataTime'),//日期
    oOrgWorkTimeStart   = $('#orgWorkTimeStart'),//进场时间/工地
    oOrgWorkTimeEnd     = $('#orgWorkTimeEnd'),//出场时间/工地
    oWorkTime           = $('#workTime'),//工数/工地
    oChgWorkTimeStart   = $('#chgWorkTimeStart'),//进场时间/调整
    oChgWorkTimeEnd     = $('#chgWorkTimeEnd'),//出场时间/调整
    oChangeReason       = $('#changeReason'),//调整原因
    oChgWorkTimeAdjust  = $('#chgWorkTimeAdjust'),//调整工数
    oUnitSalary         = $('#unitSalary'),//工价/元
    oActualSalary       = $('#actualSalary');//实际金额/元

var
    oDataTimeVal = '',
    oOrgWorkTimeStartVal = '',
    oOrgWorkTimeEndVal = '',
    oWorkTimeVal = '',
    oChgWorkTimeStartVal ='',
    oChgWorkTimeEndVal = '',
    oChangeReasonVal = '',
    oChgWorkTimeAdjustVal = '',
    oUnitSalaryVal = '',
    oActualSalaryVal = '';


$('#saveBtn').click(function(){
    oDataTimeVal            =   oDataTime.val(),
    oOrgWorkTimeStartVal    =   oOrgWorkTimeStart.val(),
    oOrgWorkTimeEndVal      =   oOrgWorkTimeEnd.val(),
    oWorkTimeVal            =   oWorkTime.val(),
    oChgWorkTimeStartVal    =   oChgWorkTimeStart.val(),
    oChgWorkTimeEndVal      =   oChgWorkTimeEnd.val(),
    oChangeReasonVal        =   oChangeReason.val(),
    oChgWorkTimeAdjustVal   =   oChgWorkTimeAdjust.val(),
    oUnitSalaryVal          =   oUnitSalary.val(),
    oActualSalaryVal        =   oActualSalary.val();


console.log(json);
    oData = [{
        "dataTime"          : oDataTimeVal,
        "orgWorkTimeStart"  : oOrgWorkTimeStartVal,
        "orgWorkTimeEnd"    : oOrgWorkTimeEndVal,
        "workTime"          : oWorkTimeVal,
        "unitSalary"        : oUnitSalaryVal,
        "projectCode"       : json.projectCode,
        "teamId"            : json.teamId,
        "userCode"          : json.userCode
    }];
    console.log(oData);

    /*oData = {
        "dataTime"          : oDataTimeVal,
        "orgWorkTimeStart"  : oOrgWorkTimeStartVal,
        "orgWorkTimeEnd"    : oOrgWorkTimeEndVal,
        "workTime"          : oWorkTimeVal,
        "chgWorkTimeStart"  : oChgWorkTimeStartVal,
        "chgWorkTimeEnd"    : oChgWorkTimeEndVal,
        "changeReason"      : oChangeReasonVal,
        "chgWorkTimeAdjust" : oChgWorkTimeAdjustVal,
        "unitSalary"        : oUnitSalaryVal,
        "actualSalary"      : oActualSalaryVal
    };*/

    $.ajax({
        type : 'POST',
        data: JSON.stringify(oData),
        url : 'http://192.168.59.3:8082/console/material',
        dataType : 'json',
        contentType : 'application/json',

        success : function (data){
            console.log(data);
            $("#workTable").bootstrapTable('refresh','http://192.168.59.3:8082/console/material/equipmentTypeDetailList?projectCode=${json.projectCode}&equipmentType=${json.equipmentType}');
        },
        error : function (err){
            console.log( err.responseText);
        }
    })
});

function responseHandler(res) {
    var needData = {
        rows: res.data,
        total: res.total
    };
    return needData;
}
